package cn.sample.moreitems.init;

import cn.sample.moreitems.MoreItems;
import cn.sample.moreitems.entity.TechnologyEntity;
import cn.sample.moreitems.menu.TechnologyMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.extensions.IForgeMenuType;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class ModMenu {

    public static final DeferredRegister<MenuType<?>> MENU_TYPES =
            DeferredRegister.create(ForgeRegistries.MENU_TYPES, MoreItems.MODID);

    public static final RegistryObject<MenuType<TechnologyMenu>> THROWN_ROCK = MENU_TYPES.register("technology_menu",
            () -> IForgeMenuType.create((windowId, inv, buf) -> {
                BlockPos pos = buf.readBlockPos();
                ContainerLevelAccess access = ContainerLevelAccess.create(inv.player.level(), pos);
                // 客户端侧 Level 是 ClientLevel，也能查到 ClientBlockEntity
                BlockEntity be = inv.player.level().getBlockEntity(pos);
                return new TechnologyMenu(windowId, inv, access, (TechnologyEntity) be);
            }));


}
